# models.py
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

db = SQLAlchemy()

class Contact(db.Model):
    __tablename__ = 'contacts'
    uid = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(db.String(1000), unique=True, nullable=False)
    email = db.Column(db.String(120), nullable=False)
    cellphone = db.Column(db.String(20), nullable=False)
    address = db.Column(db.String(100),nullable=True)

class Email(db.Model):
    __tablename__ = 'emails'
    eid = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120), nullable=False)
    uid = db.Column(db.Integer, db.ForeignKey('contacts.uid'), nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.utcnow)
    textbody = db.Column(db.Text, nullable=False)
    reply_id = db.Column(db.Integer, db.ForeignKey('emails.eid'))
    is_deleted = db.Column(db.Boolean, default=False)

class MailRecipient(db.Model):
    __tablename__ = 'mail_recipients'
    mid = db.Column(db.Integer, primary_key=True)
    eid = db.Column(db.Integer, db.ForeignKey('emails.eid'), nullable=False)
    uid = db.Column(db.Integer, db.ForeignKey('contacts.uid'), nullable=False)
